﻿namespace LeetCodeProject._0001_1000._101_200._111_120._115;

public class Solution
{
    public int NumDistinct(string s, string t)
    {
        int m = s.Length;
        int n = t.Length;
        if (m < n)
            return 0;

        int[][] dp = new int [m + 1][];
        for (int i = 0; i <= m; i++)
        {
            dp[i] = new int[n + 1];
            dp[i][0] = 1;
        }

        for (int i = 1; i <= m; i++)
        {
            char c1 = s[i - 1];
            for (int j = 1; j <= n; j++)
            {
                char c2 = t[j - 1];
                if (c1 == c2)
                {
                    dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
                }
                else
                {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }

        return dp[m][n];
    }
}